using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Commerce.Common
{
	/// <summary>
	/// Strongly-typed collection for the UtilZipCode class.
	/// </summary>
	[Serializable]
	public partial class UtilZipCodeCollection : ActiveList<UtilZipCode,UtilZipCodeCollection> 
	{	   
		public UtilZipCodeCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the CSK_Util_ZipCode table.
	/// </summary>
	[Serializable]
	public partial class UtilZipCode : ActiveRecord<UtilZipCode>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public UtilZipCode()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public UtilZipCode(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

        
		public UtilZipCode(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public UtilZipCode(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }

		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("CSK_Util_ZipCode", TableType.Table, DataService.GetInstance("dashCommerce"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarZipCodeID = new TableSchema.TableColumn(schema);
				colvarZipCodeID.ColumnName = "zipCodeID";
				colvarZipCodeID.DataType = DbType.Int32;
				colvarZipCodeID.MaxLength = 0;
				colvarZipCodeID.AutoIncrement = true;
				colvarZipCodeID.IsNullable = false;
				colvarZipCodeID.IsPrimaryKey = true;
				colvarZipCodeID.IsForeignKey = false;
				colvarZipCodeID.IsReadOnly = false;
				colvarZipCodeID.DefaultSetting = @"";
				colvarZipCodeID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarZipCodeID);
				
				TableSchema.TableColumn colvarStateAbbreviation = new TableSchema.TableColumn(schema);
				colvarStateAbbreviation.ColumnName = "stateAbbreviation";
				colvarStateAbbreviation.DataType = DbType.String;
				colvarStateAbbreviation.MaxLength = 2;
				colvarStateAbbreviation.AutoIncrement = false;
				colvarStateAbbreviation.IsNullable = true;
				colvarStateAbbreviation.IsPrimaryKey = false;
				colvarStateAbbreviation.IsForeignKey = false;
				colvarStateAbbreviation.IsReadOnly = false;
				colvarStateAbbreviation.DefaultSetting = @"";
				colvarStateAbbreviation.ForeignKeyTableName = "";
				schema.Columns.Add(colvarStateAbbreviation);
				
				TableSchema.TableColumn colvarZipCode = new TableSchema.TableColumn(schema);
				colvarZipCode.ColumnName = "zipCode";
				colvarZipCode.DataType = DbType.String;
				colvarZipCode.MaxLength = 12;
				colvarZipCode.AutoIncrement = false;
				colvarZipCode.IsNullable = true;
				colvarZipCode.IsPrimaryKey = false;
				colvarZipCode.IsForeignKey = false;
				colvarZipCode.IsReadOnly = false;
				colvarZipCode.DefaultSetting = @"";
				colvarZipCode.ForeignKeyTableName = "";
				schema.Columns.Add(colvarZipCode);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["dashCommerce"].AddSchema("CSK_Util_ZipCode",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("ZipCodeID")]
		public int ZipCodeID 
		{
			get { return GetColumnValue<int>(Columns.ZipCodeID); }

			set { SetColumnValue(Columns.ZipCodeID, value); }

		}

		  
		[XmlAttribute("StateAbbreviation")]
		public string StateAbbreviation 
		{
			get { return GetColumnValue<string>(Columns.StateAbbreviation); }

			set { SetColumnValue(Columns.StateAbbreviation, value); }

		}

		  
		[XmlAttribute("ZipCode")]
		public string ZipCode 
		{
			get { return GetColumnValue<string>(Columns.ZipCode); }

			set { SetColumnValue(Columns.ZipCode, value); }

		}

		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(string varStateAbbreviation,string varZipCode)
		{
			UtilZipCode item = new UtilZipCode();
			
			item.StateAbbreviation = varStateAbbreviation;
			
			item.ZipCode = varZipCode;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varZipCodeID,string varStateAbbreviation,string varZipCode)
		{
			UtilZipCode item = new UtilZipCode();
			
				item.ZipCodeID = varZipCodeID;
			
				item.StateAbbreviation = varStateAbbreviation;
			
				item.ZipCode = varZipCode;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn ZipCodeIDColumn
        {
            get { return Schema.Columns[0]; }

        }

        
        
        
        public static TableSchema.TableColumn StateAbbreviationColumn
        {
            get { return Schema.Columns[1]; }

        }

        
        
        
        public static TableSchema.TableColumn ZipCodeColumn
        {
            get { return Schema.Columns[2]; }

        }

        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string ZipCodeID = @"zipCodeID";
			 public static string StateAbbreviation = @"stateAbbreviation";
			 public static string ZipCode = @"zipCode";
						
		}

		#endregion
		
		
		
	}

}

